<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-11-23 14:20
 *
 * Version: 2.0
 */

namespace App\Modules\Coupon\Transformers;


use League\Fractal\TransformerAbstract;

class GetStoreCouponListTransformer extends TransformerAbstract
{
	public static function transform($list)
	{
		$memberList = empty($list['receiveList']) ? [] : array_column($list['receiveList'],null,'coupon_id');
		$data = array_map(function ($v) use ($memberList) {
			return [
				"id"              => $v['id'],
				"name"            => $v['name'],
				"type"            => $v['type'],
				"money"           => $v['money'],
				"discount"        => $v['discount'],
				"use_condition"   => $v['use_condition'],
				"no_send_num"     => $v['createnum'] - $v['send_num'],
				"use_start_time"  => $v['use_start_time'],
				"use_end_time"    => $v['use_end_time'],
				"send_start_time" => $v['send_start_time'],
				"send_end_time"   => $v['send_end_time'],
				"status"          => isset($memberList[$v['id']]) ? 1 : 0,
			];
		}, $list['couponList']);
		return ['status'=>1,'msg'=>'获取信息成功','data'=>$data];
	}
}